<?php
session_start();
/**
Eventos de FrmTableRoles
**/
//Variables de session
$_SESSION['tableRolesIdOrder'];//0 Asc 1 Desc
$_SESSION['tableRolesNombreOrder'];
//-------------------

//MApache
require("../../../weblinx/weblinx.php");
//-------

//----Formularios requeridos----

//------------------------------

//----Clases requeridas---------
require("../../Classes/Setter.php");
require("../../Classes/Sentinel.php");
require("../../Classes/Admin/Rol.php");
require("../../Forms/Admin/FrmTableRoles.php");
require("../../Forms/Admin/FrmRolEdit.php");
require("../../Forms/Admin/FrmRolInfo.php");
//-----------------------------

//---Events--------------------

if(isset($_POST['editar'])){
	$rol=new Rol();
	$rol->cargar($_POST['editar']);
	$frmRolEdit=new FrmRolEdit($rol);
	$frmRolEdit->show();
}
else if(isset($_POST['eliminar'])){
	$rol=new Rol();
	$rol->cargar($_POST['eliminar']);
	if($rol->getNombre()=="invitado" || $rol->getNombre()=="Administrador"){
		$messageBox=new MessageBox($image="../../../weblinx/Images/info.png",$messageText="<b>No se puede eliminar los roles invitado y Administrador</b>",$okButtonName="okValidatorFrmRolEliminarNo",$okButtonValue="ok",$okButtonEvents=array("onclick"=>"GETMethodSend('okValidatorFrmRolEliminarNo','tableRoles','../../Events/Admin/EventsFrmTableRoles.php')"),$cancelButtonName="cancelValidatorFrmRolEliminarNo",$cancelButtonValue="cancel",$cancelButtonEvents=array("onclick"=>"GETMethodSend('cancelValidatorFrmRolEliminarNo','tableRoles','../../Events/Admin/EventsFrmTableRoles.php')"));
		$messageBox->setVisible("visible");
		$messageBox->show();
	}
	else{
		$messageBox=new MessageBox($image="../../../weblinx/Images/danger.png",$messageText="<b>¿Segur@ que quiere eliminar a este rol? <br /> Id: ".$_POST['eliminar']." </b>",$okButtonName="okValidatorFrmRolEliminar",$okButtonValue="ok",$okButtonEvents=array("onclick"=>"GETMethodSend('idE','okValidatorFrmRolEliminar','tableRoles','../../Events/Admin/EventsFrmTableRoles.php')"),$cancelButtonName="cancelValidatorFrmRolEliminar",$cancelButtonValue="cancel",$cancelButtonEvents=array("onclick"=>"GETMethodSend('cancelValidatorFrmRolEliminar','tableRoles','../../Events/Admin/EventsFrmTableRoles.php')"));
		$messageBox->addHiddenData("idE",$_POST['eliminar']);
		$messageBox->setVisible("visible");
		$messageBox->show();
	}	
}
else if(isset($_GET['okValidatorFrmRolEliminar'])){
	$rol=new Rol();
	$rol->cargar($_GET['idE']);
	$rol->eliminar();
	
	$frmTableRoles=new FrmTableRoles();
	$frmTableRoles->show();
}
else if(isset($_GET['cancelValidatorFrmRolEliminar'])){
	$frmTableRoles=new FrmTableRoles();
	$frmTableRoles->show();
}
else if(isset($_GET['okValidatorFrmRolEliminarNo'])){
	$frmTableRoles=new FrmTableRoles();
	$frmTableRoles->show();
}
else if(isset($_GET['cancelValidatorFrmRolEliminarNo'])){
	$frmTableRoles=new FrmTableRoles();
	$frmTableRoles->show();
}

else if(isset($_POST['masInfo'])){
	$rol=new Rol();
	$rol->cargar($_POST['masInfo']);
	
	$frmRolInfo=new FrmRolInfo($rol);
	$frmRolInfo->show();
}

//Ordenamiento por los titulos de la tabla
else if(isset($_POST['id'])){
	if($_SESSION['tableRolesIdOrder']==0){
		$consult="SELECT id,nombre,descripcion FROM roles ORDER BY id ASC";
		$_SESSION['tableRolesIdOrder']=1;
	}
	else{
		$consult="SELECT id,nombre,descripcion FROM roles ORDER BY id DESC";
		$_SESSION['tableRolesIdOrder']=0;
	}
	$frmTableRoles=new FrmTableRoles();
	$frmTableRoles->setDbConsult($consult);
	$frmTableRoles->show();
}

else if(isset($_POST['Nombre'])){
	if($_SESSION['tableRolesNombreOrder']==0){
		$consult="SELECT id,nombre,descripcion FROM roles ORDER BY nombre ASC";
		$_SESSION['tableRolesNombreOrder']=1;
	}
	else{
		$consult="SELECT id,nombre,descripcion FROM roles ORDER BY nombre DESC";
		$_SESSION['tableRolesNombreOrder']=0;
	}
	$frmTableRoles=new FrmTableRoles();
	$frmTableRoles->setDbConsult($consult);
	$frmTableRoles->show();
}
else if(isset($_POST['Descripcion'])){
	$frmTableRoles=new FrmTableRoles();
	$frmTableRoles->show();
}
//----------------------------------------

?>